function [ res ] = jacobian_u( xSet, uSet, pars )
% JACOBIAN_U returns the derivative of the plant dynamics with respect to
% the input vector (known as Jacobian)
% INPUTS:
%   xSet  : state values where to do linearization (Taylor expansion)
%   uSet  : input values where to do linearization (Taylor expansion)
%   pars: parameters of the plant model
%
% OUTPUT:
%  result: Jacobian matrix

% Initialization of working variables
Dx = xSet(1);
Dy = xSet(2);
Dp = xSet(3);

% Initialization of car's geometrics
m = pars.m; % 1000?
I = pars.I; % 300?
g = pars.g; % 9.81?
a = pars.a; % 1?
b = pars.b; % 1?

% Tire models by Pacejca

% Lateral / front
a1_c = -22.1;
a2_c = 1011;
a3_c = 1078;
a4_c = 1.82;
a5_c = 0.208;
a6_c = 0.000;
a7_c = -0.354;
a8_c = 0.707;
a9_c = 0.028;
a10_c = 0.000;
a11_c = 14.8;
C_c_f = 1.3;

% Longitudinal / front
a1_l = 21.3;
a2_l = 1144;
a3_l = 49.6;
a4_l = 226;
a5_l = 0.069;
a6_l = -0.006;
a7_l = 0.056;
a8_l = 0.486;
C_l_f = 1.65;

% Calculate the jacobian for given state and input
res = zeros(8,1);
res(1,:) = 0;
res(2,:) = -(2*sind(uSet)*((a11_c*b*g*m)/(2*a + 2*b) - (a3_c*cosd(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - ((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1)))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))))^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2) + 2*cosd(uSet)*(sind(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2) + uSet*((a11_c*b*g*m)/(2*a + 2*b) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2)) - 2*sind(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(uSet)*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2) - (2*exp(-(a5_l*b*g*m)/(2*a + 2*b))*cosd(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*cosd(uSet)*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_l - (a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)/(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))^2*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2 + 1) + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))/((exp(-(2*a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))^2*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2)/(C_l_f^2*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1))/m;
res(3,:) = 0;
res(4,:) = (2*cosd(uSet)*((a11_c*b*g*m)/(2*a + 2*b) - (a3_c*cosd(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - ((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1)))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))))^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2) - 2*sind(uSet)*(sind(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2) + uSet*((a11_c*b*g*m)/(2*a + 2*b) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2)) - 2*cosd(uSet)*sind(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2) + (2*exp(-(a5_l*b*g*m)/(2*a + 2*b))*cosd(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(uSet)*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_l - (a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)/(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))^2*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2 + 1) + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))/((exp(-(2*a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))^2*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2)/(C_l_f^2*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1))/m;
res(5,:) = 0;
res(6,:) = (2*a*(cosd(uSet)*((a11_c*b*g*m)/(2*a + 2*b) - (a3_c*cosd(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - ((a9_c - 1)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1)))/((a3_c^2*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))^2*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))))^2)/(C_c_f^2*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2) - sind(uSet)*(sind(C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*((atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1) - (C_c_f*atand((a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b)))*(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a))) - a9_c*uSet))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_c + (a7_c*b*g*m)/(2*a + 2*b) + (a6_c*b^2*g^2*m^2)/(2*a + 2*b)^2))/(a3_c*sind(a4_c*atand((a5_c*b*g*m)/(2*a + 2*b))))))/(C_c_f*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2))))*((a2_c*b*g*m)/(2*a + 2*b) + (a1_c*b^2*g^2*m^2)/(2*a + 2*b)^2) + uSet*((a11_c*b*g*m)/(2*a + 2*b) + (a10_c*b^2*g^2*m^2)/(2*a + 2*b)^2)) - cosd(uSet)*sind(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2) + (exp(-(a5_l*b*g*m)/(2*a + 2*b))*cosd(C_l_f*atand((exp(-(a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2))/(C_l_f*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2))))*sind(uSet)*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)*(a8_l - (a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)/(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))^2*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2 + 1) + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))/((exp(-(2*a5_l*b*g*m)/(2*a + 2*b))*(atand(atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2)) - atand((Dx*sind(uSet) - cosd(uSet)*(Dy + Dp*a))/(Dx*cosd(uSet) + sind(uSet)*(Dy + Dp*a)))*(a8_l + (a7_l*b*g*m)/(2*a + 2*b) + (a6_l*b^2*g^2*m^2)/(2*a + 2*b)^2 - 1))^2*((a4_l*b*g*m)/(2*a + 2*b) + (a3_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2)/(C_l_f^2*((a2_l*b*g*m)/(2*a + 2*b) + (a1_l*b^2*g^2*m^2)/(2*a + 2*b)^2)^2) + 1)))/I;
res(7,:) = 0;
res(8,:) = 0;

end

